;( function( H )
{
    // 设置维度选项
    H.setAxisSelect = function( text, value )
    {
        if( text && value )
        {
            var select = "<select name='values'>";

            var array = value.split(",");
            var arraytext = text.split("，");

            for( var i = 0, f; f = array[ i ]; i += 1 )
            {
                select += "<option value='" + f + "'>" + arraytext[ i ] + "</option>"
            }

            return select + "</select>";
        }
        else
        {
            return "无";
        }
    }

    // 设置统计值
    H.setAxisValue = function( value )
    {
        if( value )
        {
            return value.split(",")[ 0 ];
        }
        else
        {
            return "null";
        }
    }

    // 设置单位
    H.setUom = function( uom )
    {
        if( uom )
        {
            var value = parseInt( uom, 10 );

            switch( value )
            {
                case 1: return "元";
                case 2: return "万元";
                case 3: return "亿元";
                case 4: return "平方米";
                case 5: return "万平方";
                case 6: return "亿平方";
                case 7: return "元/平方米";
                case 8: return "元/套";
                case 9: return "万元/套";
                case 10: return "套";
                default : return "未知";
            }
        }
        return "null";
    }

    // 预计价格
    H.expectPrice = function( value )
    {
        if( parseInt( value, 10 ) )
        {
            return  Math.ceil( value );
        }
        else
        {
            return "-"
        }
    }

    // 成交方式
    H.wayHandle = function( value )
    {
        value = parseInt( value, 10 );

        switch( value )
        {
            case 0 : return "未成交";
            case 1 : return "拍卖";
            case 2 : return "挂牌";
            case 3 : return "流拍&终止挂牌";
            default : return "未知";
        }

    }

    // 流拍不显示数据
    H.way3Nodata = function( num, way )
    {
        if( way == 3 ) return null;

        return num;
    };

    // 保留位置 type 0 整数 2 两位小数
    H.retainNumber = function( num, type )
    {
        if( !num ) return num || "-";

        return parseFloat(num).toFixed( parseInt(type,10) ? parseInt(type,10) : 0 );
    };

    // 输出项目业态
    H.printTabs = function( array )
    {
        var result = "";
        var tabTitle = "<dl class='ad-doc-protabs'>";
        var title = "";
        var tabContent = "<div class='ad-doc-protabscontent'>";
        var content = "";

        var handleYid = function( value )
        {
            if( !value ) return "未知";

            value = parseInt( value, 10 );

            switch( value )
            {
                case 1 : return "别墅";
                case 2 : return "洋房";
                case 3 : return "洋楼";
                case 4 : return "高层";
                case 5 : return "小高层";
                case 6 : return "商铺";
                case 7 : return "商务";
                case 8 : return "经济";
                case 9 : return "车库";
                case 10 : return "其他";
                default : return "其他";
            }
        };

        for( var i = 0, f; f = array[ i ]; i += 1 )
        {
            title += "<dd" + ( !i ? " class='active'" : "" )+ ">" + handleYid( f["yid"] )  + "</dd>";
            content += '<div' + ( !i ? ' class="active"' : '' )+ '>' +
                '<div class="ad-doc-b-list-fst">' +
                '<div><i class="fa fa-angle-right"></i> 套内均价：<span>' + ( this.retainNumber( f["jj"], "int" ) || "-" )+'</span> 元/㎡</div>' +
                '</div>' +
                '<div>' +
                '<div><i class="fa fa-angle-right"></i> 面积区间：' + ( parseInt( f["minMJ"], 10 ) || "-" ) + ' ㎡ - ' + ( parseInt( f["maxMJ"], 10 ) || "-" ) +'  ㎡</div>' +
                '</div><em class="clear"></em></div>';
        }

        result += tabTitle+ title + "</dl>";
        result += tabContent + content + "</div>";

        return result;

    }

    // 呈现项目
    H.setProjectName = function( project, projectsrc )
    {
        if( project )
        {
            project = project.split(",");

            var res = [];

            for( var i = 0, f; f = project[ i ]; i += 1 )
            {
                res.push("<samp data-projectsrc='"+ projectsrc + "'>「 " + f + " 」</samp>");
            }

            return res.join(" ");
        }

        return "";
    }

    // 成交总价
    H.totalTurnover = function( value )
    {
        if( parseInt( value, 10 ) )
        {
            return Math.ceil( value );
        }
        else
        {
            return "-"
        }
    };

    /** 日期转换*/
    H.dateFormat = function( value )
    {
        if( parseInt( value, 10 ) )
        {
            return (function ( now )
            {
                var year = now.getFullYear();
                var month = now.getMonth() + 1;
                var date = now.getDate();

                return year + "年" + month + "月" + date + "日";
            })( new Date( parseInt( value, 10 ) * 1000 ) );
        }
        else
        {
            return "-"
        }
    };

    /** 输出关注*/
    H.getGz = function( status )
    {
        if( status == 2 )
        {
            return "";
        }
        else if( status == 1 )
        {
            return "<div class='gz active'>已关注</div>";
        }
        else
        {
            return "<div class='gz'>+ 关注</div>";

        }
    };

    /** 输出关注*/
    H.getGz2 = function( status )
    {
        if( status == 2 )
        {
            return "";
        }
        else if( status == 1 )
        {
            return "<div class='gz active'>已关注</div>";
        }
        else
        {
            return "<div class='gz'>+ 关注</div>";

        }
    };


    /** 日期转换*/
    H.dateFormat2 = function( value )
    {
        if( parseInt( value, 10 ) )
        {
            return (function ( now )
            {
                var year = now.getFullYear();
                var month = now.getMonth() + 1;
                var str = "";

                if( 0 <= month && month <= 3 )
                {
                    str = "一季度";
                }
                else if( 3 <= month && month <= 6 )
                {
                    str = "二季度";
                }
                else if( 6 <= month && month <= 9 )
                {
                    str = "三季度";
                }
                else if( 9 <= month && month <= 12 )
                {
                    str = "四季度";
                }

                return year + "年 " + str;

            })( new Date( parseInt( value, 10 ) * 1000 ) );
        }
        else
        {
            return "-"
        }
    };

    /** 转换性质*/
    H.changeNature  = function( value )
    {
        if( !value ) return '<span class="default">未知</span>';

        value = Math.ceil( value );

        var str = "";
        var color = "";

        // 1：商业；2：居住；3：商兼住；4：住兼商
        switch( value )
        {
            case 1 :
                str = "商业";
                color = "red";
                break;
            case 2 :
                str = "居住";
                color = "yellow";
                break;
            case 3 :
                str =  "商兼住";
                color = "lightred";
                break;
            case 4 :
                str =  "住兼商";
                color = "deeptred";
                break;
            default :
                str = "未知";
                color = "default"
        }

        return '<span class="' + color + '">' + str + '</span>';
    }

    /** 溢价率转换*/
    H.premiumRate  = function( value, way )
    {
        if( way == 0 || way == 3 )
        {
            if( value == 0 ) return "-";
        }
        else
        {
            if( value == 0 ) return "0%";
        }

        return Math.ceil( value ) + "%";
    }

})( window.Handle || {} );